home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3689 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  49 lines

  1. Path: locutus.rchland.ibm.com!usenet
  2. From: Philip Staite <pstaite@vnet.ibm.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Converting dates in MMYY to YYMMDD format
  5. Date: Thu, 25 Jan 1996 10:41:34 -0600
  6. Organization: IBM Rochester, OS/2 Device Driver Team
  7. Message-ID: <3107B2BE.794B@vnet.ibm.com>
  8. References: <4e6ms8$ad5@walrus2.walrus.com>
  9. NNTP-Posting-Host: powertool.rchland.ibm.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b4 (X11; I; AIX 1)
  14.  
  15. Felipe Jordao wrote:
  16. > Hi,
  17. > I have a rather clumsy function that converts a character string in
  18. > MMYY format, (such as 1195 for November 1995) into a long DDMMYY
  19. > format, where DD is always the last day of the month.  Hence "1282"
  20. > would be converted into 821231 (a long).
  21. > Does anyone know a quick way of doing this (around 10-20 lines of
  22. > code)?#include<iostream.h>
  23.  
  24. Your example output looks like YYMMDD not DDMMYY...  Anyway, try this:
  25.  
  26. #include<iostream.h>   
  27.  
  28. long mn[ 12 ] = { 31, 28, 31, 30, 31, 30,
  29.                   31, 31, 30, 31, 30, 31 };
  30.  
  31. int main() {
  32.     long n;
  33.     cin >> n;  // get date
  34.     cout << ( mn[ n / 100 - 1 ] + ( n / 100 ) * 100 + ( n % 100 ) *
  35. 10000 ) << endl;
  36.     return 0; }
  37.  
  38.  
  39.  
  40.  
  41. -- 
  42.  
  43. Phil Staite, (507) 253-2529, team OS/2
  44. internet: pstaite@vnet.ibm.com  internal: pstaite@rchland
  45.